 subroutine getpqrvv_ri2(icore, iin, irrepiin, rivva,rivvb,ioppq, ispin)
! One should note that the memory in getpqr is nabc*2 
! so the memory size of icore must be carefully treatted
! ispin = 1 aa; ispin = 2 bb; ispin=3 ab
 use mod_ri
 use mod_iop
 use mod_symm
 use mod_orbit
 implicit none 
!----------------------------------
 integer, intent(in) ::  iin, irrepiin,ioppq, ispin
 real*4, intent(in) :: rivva(*), rivvb(*)
 real*4, intent(out) :: icore(*)

 integer irrep, n, a, b, c, d
 integer numa, numb, numc, numd
 integer numab, numcd, ioff, nabc, ioffd,ioffd2(2000, 8), ioffout
 integer irrepa, irrepb, irrepc, irrepd, numnb, i0, i1
 integer irrepab, irrepcd, nsize, ioffabc, numna
 integer irrepi, numi, i, ioffi, ioffvo(8), ioffi2(2000, 8), irrepiin
 integer, external :: irpdso, idsymsoc, isymoffso
 real*8, external :: nrm2so

    zorb(1:8) = 0 
    zorb(1) = 1
 if(ispin==1) then 
!AAAA
         nabc = idsymsoc(irrepiin, vrta, vrta, 1, vrta, zorb, 1)
          irrepi = irrepiin
          i0 = 1
          i1 = i0 + max(nabc*isd, idsymsoc(irrepiin, naux8, zorb, 1, vrta, zorb, 1))
          call getpqrso_incore(icore, iin, irrepi, naux8, zorb, 1, vrta, vrta, 1, rivva, 1)
          call VmnpqVmnrs_to_Vpqrs(rivva, icore, 1, irrepi, naux8, zorb, 1, vrta, vrta, 1, &
                        vrta, zorb, 1, icore(i1), irrepi, 1.d0, 0.d0)
          call sstgenso(icore(i1), icore,  nsize, vrta, vrta, vrta, zorb, icore,&
                        irrepi, '1324')
!!!!<AB||CD> = <AB|CD> - <BA|CD>
          if(ioppq==0) then 
             call isymtrso(icore, icore(i1), vrta, vrta, 1, 1, vrta, zorb, 1, 0, irrepi)
             call axpyso(nabc, -1.d0, icore(i1), 1, icore, 1)
             call icompso(icore, icore(i1), vrta, vrta, 1, 0, vrta, zorb, 1, 1,irrepi) 
             nabc = idsymsoc(irrepi, vrta, vrta, 0, vrta, zorb, 1) 
             call myicopyso(icore(i1), icore, nabc)
          endif
 elseif(ispin==2) then 
!BBBB
          nabc = idsymsoc(irrepiin, vrtb, vrtb, 1, vrtb, zorb, 1)
          irrepi = irrepiin
          i0 = 1
          i1 = i0 + max(nabc*isd, idsymsoc(irrepiin, naux8, zorb, 1, vrtb, zorb, 1))
          call getpqrso_incore(icore, iin, irrepi, naux8, zorb, 1, vrtb, vrtb, 1, rivvb, 1)
          call VmnpqVmnrs_to_Vpqrs(rivvb, icore, 1, irrepi, naux8, zorb, 1, vrtb, vrtb, 1, &
                        vrtb, zorb, 1, icore(i1), irrepi, 1.d0, 0.d0)
          call sstgenso(icore(i1), icore,  nsize, vrtb, vrtb, vrtb, zorb, icore,&
                        irrepi, '1324')
!!!!<AB||CI> = <AB|CI> - <BA|CI>
          if(ioppq==0) then 
             call isymtrso(icore, icore(i1), vrtb, vrtb, 1, 1, vrtb, zorb, 1, 0, irrepi)
             call axpyso(nabc, -1.d0, icore(i1), 1, icore, 1)
             call icompso(icore, icore(i1), vrtb, vrtb, 1, 0, vrtb, zorb, 1, 1,irrepi) 
             nabc = idsymsoc(irrepi, vrtb, vrtb, 0, vrtb, zorb, 1) 
             call myicopyso(icore(i1), icore, nabc)
          endif
 elseif(ispin==3) then 
!ABAB
          if(ioppq==0) then 
             write(6,*)'error in ioppq of getpqrvo_ri_uhf'
          endif
          nabc = idsymsoc(irrepiin, vrta, vrtb, 1, vrta, zorb, 1)
          irrepi = irrepiin
          i0 = 1
          i1 = i0 + max(nabc*isd, idsymsoc(irrepiin, naux8, zorb, 1, vrtb, zorb, 1))
          call getpqrso_incore(icore, iin, irrepi, naux8, zorb, 1, vrtb, vrtb, 1, rivvb,1)
          call VmnpqVmnrs_to_Vpqrs(rivva,icore, 1, irrepi, naux8, zorb, 1, vrta, vrta, 1, &
                        vrtb, zorb, 1, icore(i1), irrepi, 1.d0, 0.d0)
          call sstgenso(icore(i1), icore,  nsize, vrta, vrta, vrtb, zorb, icore,&
                        irrepi, '1324')
  endif
  return
  end
